

package com.hazelcast.test.starter.constructor;

import com.hazelcast.test.starter.HazelcastStarterConstructor;

import java.lang.reflect.Constructor;

import static com.hazelcast.test.starter.ReflectionUtils.getFieldValueReflectively;

@HazelcastStarterConstructor(classNames = {"com.hazelcast.internal.serialization.impl.HeapData"})
public class HeapDataConstructor extends AbstractStarterObjectConstructor {

    public HeapDataConstructor(Class<?> targetClass) {
        super(targetClass);
    }

    @Override
    Object createNew0(Object delegate) throws Exception {
        // obtain reference to constructor HeapData(byte[] payload)
        Constructor<?> constructor = targetClass.getDeclaredConstructor(byte[].class);

        byte[] payload = (byte[]) getFieldValueReflectively(delegate, "payload");
        Object[] args = new Object[]{payload};

        return constructor.newInstance(args);
    }
}
